package kr.saeildamil.androidstudy.ch11;

import kr.saeildamil.androidstudy.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;





public class Radiocheck extends Activity {
	TextView mSample;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch11_radiocheck);
		
		mSample = (TextView) findViewById(R.id.ch11_radiocheck_tv);
		
		RadioGroup radiogrp = (RadioGroup) findViewById(R.id.ch11_radiocheck_radiogroup);
		CheckBox chkBox = (CheckBox) findViewById(R.id.ch11_radiocheck_chkwhiteback);
		ToggleButton tglBtn = (ToggleButton) findViewById(R.id.ch11_radiocheck_tgllanguage);
		
		RadioGroup.OnCheckedChangeListener radioListener = new RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if(group.getId() == R.id.ch11_radiocheck_radiogroup){
					switch(checkedId){
					case R.id.ch11_radiocheck_rared:
						mSample.setTextColor(Color.RED);
						break;
					case R.id.ch11_radiocheck_ragreen:
						mSample.setTextColor(Color.GREEN);
						break;
					case R.id.ch11_radiocheck_rablue:
						mSample.setTextColor(Color.BLUE);
						break;
					}
				}
				
			}
		};
		
		
		radiogrp.setOnCheckedChangeListener(radioListener);
		chkBox.setOnCheckedChangeListener(listener);
		tglBtn.setOnCheckedChangeListener(listener);
	}
	
	
	CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {
		
		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			if(buttonView.getId() == R.id.ch11_radiocheck_chkwhiteback){
				if(isChecked){
					mSample.setBackgroundColor(Color.BLACK);
				}else{
					mSample.setBackgroundColor(Color.TRANSPARENT);
				}
				
			}
			if(buttonView.getId() == R.id.ch11_radiocheck_tgllanguage){
				if(isChecked){
					mSample.setText("샘플");
				}else{
					mSample.setText("Sample");
				}
			}
		}
	};
	
}
